﻿using Microsoft.AspNetCore.Mvc;
using SiteApp.BLL.Interface;
using SiteApp.Web.Model;
using System.Linq;
using System.Threading.Tasks;

namespace SiteApp.Web.Controllers
{
    [ApiController]
    [Route("[controller]")]
    /// <summary>
    /// 与配置相关接口
    /// </summary>
    /// <returns></returns>
    public class CommonController : ControllerBase
    {
        // 电站 电压 设备

        private readonly ISiteService siteService = null;

        private bool IsValid()
        {
            if (HttpContext.User.Claims.ToList() != null && HttpContext.User.Claims.ToList()[0].Type == "IsAuthenticated" && HttpContext.User.Claims.ToList()[0].Value == "true")
            {
                return true;
            }
            return false;
        }



        public CommonController(
             ISiteService site)
        {
            this.siteService = site;
        }

        /// <summary>
        /// 获取所有的电站
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Route("GetAllSite")]
        public async Task<JsonResult> GetAllSite([FromForm]  string userId)
        {
            var result = new WebResult();

            if (IsValid())
            {
                result.Data = siteService.GetAllSite(userId);
            }
            return new JsonResult(result);
        }

        /// <summary>
        /// 获取电站下所有的设备
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Route("GetAllPoint")]
        public  async Task<JsonResult> GetAllPoint([FromForm]  string siteId)
        {
            var result = new WebResult();
            if (IsValid())
            {
                result.Data = siteService.GetAllDevice(siteId);
            }
            return new JsonResult(result);
        }



    }
}
